<template>
  <ul id="reward-list" v-infinite-scroll="getReward" infinite-scroll-disabled="busy"
      infinite-scroll-distance="30">
    <li class="reward-item" v-for="item of rewardInfo" :class="[item.rpType == '1'?'good':'bad']">
      <div class="reward-item-title">
        <h2>{{item.rpReason}}</h2>
      </div>
      <p>
        <time>{{item.rpDate | formatDate}}</time>
      </p>
    </li>
    <!--正在加载提示框-->
    <li is="loading" v-if="loadShow"></li>
    <!--加载失败弹框-->
    <li is="dialog-box" :message="dialogMessage" v-if="dialogShow" @close-dialog="closeDialog" @cancle-dialog="closeDialog"></li>
    <li class="no_data" v-if="!rewardInfo.length">
      <i class="ion ion-ios-paper-outline"></i>
      <p>暂无数据
      </p>
    </li>
  </ul>
</template>
<script>
  import "../../assets/css/reward_records.scss";
  import interfaceAPI from '../../assets/js/insterface.js';
  import http from '../../assets/js/http_mixin'
  var rewardRecordUrl = interfaceAPI.rewardRecordUrl;
  export default{
    data(){
      return {
        pageTotle: '',             // 页面总数
        count: 0,                  // 计数，记录当前页面的值
        busy: false,
        rewardInfo: []       // 奖励信息
      }
    },
    mixins: [http],
    methods: {
      getReward(){
        this.getInfo({
          url: rewardRecordUrl,
          param: {
            'num': this.$route.query.empNo,
            'currentPage': this.count,
            'pageSize': '10'
          },
          success: function (response) {
            var responseData = response.body.data;
            this.pageTotle = response.body.pages;
            if (this.pageTotle > this.count) {
              if (responseData.length > 0) {
                for (var i = 0; i < responseData.length; i++) {
                  this.rewardInfo.push(responseData[i]);
                }
              }
              this.count++;
            }
            this.busy = false;
            return false;
          },
          fail: function (response) {
            this.dialogMessage = '请求失败，请稍后再试';
            this.dialogShow = true;
          }
        })
      }
    },
    mounted(){
      document.title = '奖惩记录';
    }
  }
</script>
